package edu.tongji.jiaowu.webapp.action;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.tongji.quickCRUDQ.model.CommonBean;
import com.tongji.quickCRUDQ.util.JsonDataSet;
import com.tongji.quickCRUDQ.util.StringUtil;

import edu.tongji.jiaowu.service.BasicDataManager;
import edu.tongji.jiaowu.service.VcodeManager;
import edu.tongji.jiaowu.webapp.session.SessionParameter;

public class EnrollmentChangeController extends MultiActionController {
	private BasicDataManager basicDataManager;
	private VcodeManager vcodeManager;
	
	public ModelAndView enrollmentChange(HttpServletRequest request, HttpServletResponse response){
		Map model=basicDataManager.gradeMajorMap(); 
		
		SessionParameter sessionParameter = (SessionParameter) request.getSession().getAttribute("SessionParameter");
		String year=sessionParameter.getCurrentSchoolYear();
		String semester=sessionParameter.getCurrentSchoolSemester();
		model.put("year", year);
		model.put("semester", semester);
		
		CommonBean codes = vcodeManager.findCodes("SCHOOL_YEAR");
		String years = JsonDataSet.commonbeanToJsonArray(codes, "code", "name");
		CommonBean codes2 = vcodeManager.findCodes("SCHOOL_SEMESTER");
		String semesters = JsonDataSet.commonbeanToJsonArray(codes2, "code", "name");
		model.put("years", years);
		model.put("semesters", semesters);
		
		request.setAttribute("paramMap", model);
		
		String ctype=request.getParameter("CHG_TYPE");
		String url="forward:/quick/quick.html?tableName=V_ENROLLMENT_CHANGE"+ctype;
		
		return new ModelAndView(url);
	}

	public BasicDataManager getBasicDataManager() {
		return basicDataManager;
	}

	public void setBasicDataManager(BasicDataManager basicDataManager) {
		this.basicDataManager = basicDataManager;
	}

	public VcodeManager getVcodeManager() {
		return vcodeManager;
	}

	public void setVcodeManager(VcodeManager vcodeManager) {
		this.vcodeManager = vcodeManager;
	}
	
	
}
